<template>
  <div>
    <el-dialog
      title="学生列表"
      :visible.sync="dialogVisible"
      width="800px"
      :close-on-click-modal="false"
    >
      <div style="min-height: 500px">
        <el-table :data="tableData" stripe style="width: 100%" max-height="600">
          <el-table-column prop="studentInfo" label="学生姓名">
            <template slot-scope="{ row }">
              {{ row.studentInfo.userName }}
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间" width="160">
          </el-table-column>
          <el-table-column label="操作" width="80" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="danger" size="mini" @click="handleDelete(row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
          <div slot="empty" class="emptyBg">
            <el-empty :image-size="200"></el-empty>
          </div>
        </el-table>
        <Pagination
          v-show="parseInt(pageObj.count) > 0"
          :total="parseInt(pageObj.count)"
          @change="getList"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.limit"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="custom" v-preventReClick @click="submitForm('form')"
          >提 交</el-button
        >
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  eduTeachingStudentQuery,
  eduTeachingStudentDelete,
} from '@/api/admin/teach/eduTeachingStudent.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      dialogVisible: false,
      listQuery: {
        page: 1,
        limit: 10,
        eduTeachingId: undefined,
      },
      tableData: [],
      pageObj: {},
    }
  },
  mounted() {
    Bus.$on('showDialogClasGradeView', (row) => {
      this.listQuery.eduTeachingId = row.id
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('showDialogClasGradeView')
  },
  methods: {
    async getList() {
      let res = await eduTeachingStudentQuery(this.listQuery)
      this.tableData = res.data.data
      this.pageObj = res.data
      this.dialogVisible = true
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      eduTeachingStudentDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>